//
// Author: Vladimir Migashko <migashko@gmail.com>, (C) 2011
//
// Copyright: See COPYING file that comes with this distribution
//

#ifndef FASYS_FASYS_SSERVICE_CONNECTION_HPP
#define FASYS_FASYS_SSERVICE_CONNECTION_HPP

#include <fas/inet/connection.hpp>
#include "../isubscriber.hpp"
#include "../isubscriptions.hpp"
#include "../ipublisher.hpp"
#include "tags.hpp"

namespace fasys{ namespace sservice{

namespace ai = ::fas::inet;

template<typename A, typename F>
class connection
 : public ai::mux_connection_base<A, F>
 , public isubscriber
{
  typedef ai::mux_connection_base<A, F> super;
public:

  virtual void published(const message& m)
  {
    super::get_aspect().template get<_subscribe_>().notify(*this, m);
  }

  connection()
    : subscriptions(0)
    , publisher(0)
  {
  }

  std::string uuid;
  std::string key;
  isubscriptions* subscriptions;
  ipublisher* publisher;
  
  template<typename T>
  bool _release(T& t)
  {
    if ( uuid.empty() )
      subscriptions->describe(key,  uuid, &t );
    uuid.clear();
    key.clear();
    return  super::_release(t);
  }
};

}}

#endif
